package com.nightpiter.model.objects;

import java.util.ArrayList;

import android.graphics.Point;

/**
 * 
 * @author Ilya Shurigyn (honorik@gmail.com)
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
public class Station {
	/**
	 * the Station name
	 */
	private String name;

	/**
	 * position on the screen
	 */
	private Point position;

	/**
	 * geographical coordinates
	 */
	private Point location;

	/**
	 * Schedule of working
	 */
	private Time openTime, closeTime;

	/**
	 * List of outgoing tunnels
	 */
	private ArrayList<Tunnel> tunnelList = new ArrayList<Tunnel>();

	/**
	 * List of outgoing transfers
	 */
	private ArrayList<Transfer> transferList = new ArrayList<Transfer>();

	/**
	 * constructor
	 * 
	 * @param name -
	 *            station name
	 * @param position -
	 *            position on phone screen
	 * @param location -
	 *            location on the world map
	 * @param open -
	 *            open time
	 * @param close -
	 *            close time
	 */
	public Station(String name, Point position, Point location, Time open,
			Time close) {
		this.name = name;
		this.position = position;
		this.location = location;
		this.openTime = open;
		this.closeTime = close;
	}

	/**
	 * add outgoing transition to the appropriate list
	 * 
	 * package protected
	 * 
	 * @param transition
	 *            the transition to add
	 */
	void addTransition(Transition transition) {
		if (transition instanceof Tunnel) {
			this.tunnelList.add((Tunnel) transition);
		}
		if (transition instanceof Transfer) {
			this.transferList.add((Transfer) transition);
		}
	}

	/**
	 * @return the closeTime
	 */
	public Time getCloseTime() {
		return closeTime;
	}

	/**
	 * @return the location
	 */
	public Point getLocation() {
		return location;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the openTime
	 */
	public Time getOpenTime() {
		return openTime;
	}

	/**
	 * @return the position
	 */
	public Point getPosition() {
		return position;
	}

	/**
	 * @return the transferList
	 */
	public ArrayList<Transfer> getTransfers() {
		return transferList;
	}

	/**
	 * @return the tunnelList
	 */
	public ArrayList<Tunnel> getTunnels() {
		return tunnelList;
	}

	/**
	 * @return Hub containing the station or null if the station has no
	 *         transfers
	 */
	public Hub getHub() {
		if (transferList.isEmpty()) {
			return null;
		} else {
			return transferList.get(0).getHub();
		}
	}

	@Override
	public String toString() {
		return "name: " + this.name;
	}

}
